Page({
    data: {
      currentTab: 0,
      height: 0,


      params: {
        // page: 1,
        type: 0,
        // size: 20
      },

      list:[],

      list2: [],

      loading: true,

      loading2: true



    },

  onLoad () {
    this.getHeight()
  },
  //获取屏幕高度

  getHeight() {
    var _this = this
    wx.getSystemInfo({
      success: function (res) {
        let clientHetght = res.windowHeight
        let clientWidth = res.windowWidth
        let ratio = 750 / clientWidth
        let height = clientHetght * ratio - 100
        _this.setData({
          height: height
        })
      },
    })
  },

  //头部点击切换
  tabClick (e) {
    console.log(e)
    var cur = e.currentTarget.dataset.curr

    var type = "params.type"
    this.setData({
      currentTab: cur,
      [type]: cur == 0 ? 0 : 1
    })


if (this.data.params.type == 0) {
    if (this.data.loading == false) {
      return false
    }else{
      this.getbookFriendsList(this.data.params)
    }
}

  if (this.data.params.type == 1) {
      if (this.data.loading2 == false) {
        return false
      }else{
        this.getbookFriendsList(this.data.params)
      }
  }

  },

  getbookFriendsList (params) {
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/tSdxFocus/findTSdxFocusByUserId/auth',
      data: params,
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code==200) {
          if (params.type == 0) {
            var list = res.data.data

            _this.setData({
              list: list,
              loading: false
            })
          }

          if (params.type == 1) {
            var list = res.data.data

            _this.setData({
              list2: list,
              loading2: false
            })
          }
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },

  //切换
  switchTab (event) {
    var cur = event.detail.current
    this.setData({
      currentTab: cur
    })
  },


  //互相关注操作

  allGuanzhu (e) {


    // return false
    var bookfriendid = e.currentTarget.dataset.bookfriendid

    var index = e.currentTarget.dataset.index
    this.addbookfriend(bookfriendid,index)
  },


  addbookfriend(bookfriendid,index) {

    var _this = this
    var params = {
      id: bookfriendid
    }
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/tSdxFocus/mutualBookFriend/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {
          wx.showToast({
            title: '互相关注成功',
            icon: 'none'
          })
          var type = "list2[" + index + "].type"

          _this.setData({
            [type]: 2,
            loading: true
          })
        }

      }
    })
  },


  oneGuanzhu (e) {
    var bookfriendid = e.currentTarget.dataset.bookfriendid

    var index = e.currentTarget.dataset.index

    this.cutbookfriend(bookfriendid, index)
  },



  cutbookfriend(bookfriendid, index) {

    var _this = this
    var params = {
      id: bookfriendid
    }
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/tSdxFocus/cancelMutualBookFriend/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {

          if (_this.data.currentTab == 0) {
            wx.showToast({
              title: '取消关注成功',
              icon: 'none'
            })

            var list = _this.data.list
            list.splice(index,1)

            _this.setData({
              list: list,
              loading2: true
            })
          }

          if (_this.data.currentTab == 1) {
            wx.showToast({
              title: '取消互关成功',
              icon: 'none'
            })

            var type = "list2[" + index + "].type"

            _this.setData({
              [type]: 0,
              loading: true
            })
          }
        }

      }
    })
  },



  onShow () {
    this.getbookFriendsList(this.data.params)
  }
})
